package com.wangp.mywrite.inwork.pattern._7._7_2_negative_look_around;

import com.wangp.mywrite.inwork.pattern.InitData;

/***
 * @author wangpeng
 * @since 2022-03-03  19:06
 *
 * <p>正向前查找：(?=)</p>
 * <p>负向前查找：(?!)</p>
 * <p>正向后查找：(?<=)</p>
 * <p>负向后查找：(?<!)</p>
 */
public class NegativeLookAround {


    private static final String CONTENT = "I paid $30 for 100 apples,50 oranges, and 60 pears.I saved $5 on this order.";

    /**
     * 价格获取
     */
    private static void price() {
        String priceReg = "(?<=\\$)(\\d+)";
        // [30, 5]
        System.out.println(InitData.find(CONTENT, priceReg));
    }

    /**
     * 数量获取
     */
    private static void amount() {
        // \\d+ 代码数字
        // (?<!\$) 向后查找非$符号的
        // 若不是 \b 则 $30 的 0 也会在匹配结果
        String amountReg = "\\B(?<!\\$)\\d+\\B";
        // [100, 50, 60]
        System.out.println(InitData.find(CONTENT, amountReg));
    }

    public static void main(String[] args) {
        price();
        amount();
    }
}
